var currentpage = 1,totlepage = 1,i,addTableStatus = "";//分页的当前页和总的页数
//自定义报表数据
var tableData = [],schoolData = [],schoolDataAll = [];
//报表名称 tableName:报表名称 tablePageNumber:报表每页显示的条数
var otherData = {pageLeft:0,pageRight:0,tableType:1};//1 是缴费 2 购买;// 3 优惠订单
var Page = React.createClass({
    setPage: function (e) {
        setPage($(e.target).html());
        this.props.onPageClick(1);
    },
    showPage: function () {
        showPage();
    },
    render: function () {
        {
            var items = [],
                svar = this;
            if(totlepage == 0 ){
                items.push({num:1,checked:true})
            }else if(totlepage < 6){
                for(i = 1;i <= totlepage ;i++) {
                    if (i == currentpage) {
                        items.push({num:i,checked:true})
                    } else {
                        items.push({num:i,checked:false})
                    }
                }
            }else if(currentpage >= (totlepage-2)) {//点在左边
                items.push({num:1,checked:false});
                items.push({num:'···',checked:false});
                for(i = totlepage-2;i <= totlepage ;i++){
                    if(i == currentpage){
                        items.push({num:i,checked:true})
                    }else{
                        items.push({num:i,checked:false})
                    }
                }
            }else if(currentpage <= 3){
                for(i = 1;i <= 3 ;i++) {
                    if (i == currentpage) {
                        items.push({num:i,checked:true})
                    } else {
                        items.push({num:i,checked:false})
                    }
                }
                items.push({num:'···',checked:false});
                items.push({num:totlepage,checked:false})
            }else {//点在两边
                items.push({num:1,checked:false});
                items.push({num:'···',checked:false});
                items.push({num:currentpage-1,checked:false});
                items.push({num:currentpage,checked:true});
                items.push({num:currentpage+1,checked:false});
                items.push({num:'···',checked:false});
                items.push({num:totlepage,checked:false})
            }
        }
        return (
            <div className="tableInfo-page">
                <div className="page-number">每页<span className="page-number-list" onClick={this.showPage}>{pagecount}</span>条</div>
                <div className="page-list" style={{top:pageListTop+"px"}}>
                    <ul>
                        {
                            pageList.map(function (item) {
                                return (<li onClick={svar.setPage}>{item}</li>)
                            })
                        }
                    </ul>
                </div>
                <div className="page-limit">
                    <ol className="page-limit-ol">
                        <li className="page-limit-img" name="-1" onClick={otherData.pageLeft == 0?'':svar.props.onPageClick.bind(svar,-1)}><span className={otherData.pageLeft == 0?'page-limit-left-no':'page-limit-left-yes'}/></li>
                        {
                            items.map(function (item) {
                                return (<li onClick={isNaN(item.num)?'':svar.props.onPageClick.bind(svar,item.num)}  className={item.checked == true?'page-limit-num page-limit-checked':'page-limit-num'} name={item.num}>{item.num}</li>)
                            })
                        }
                        <li className="page-limit-img" name="-2" onClick={otherData.pageRight == 0?'':svar.props.onPageClick.bind(svar,-2)}><span className={otherData.pageRight == 0?'page-limit-right-no':'page-limit-right-yes'}/></li>
                    </ol>
                </div>
            </div>
        );
    },
});
//表单组件
var Table = React.createClass({
    render: function () {
        return (
            <tr>
                <td >{parseInt(this.props.listNumber)+1}</td>
                <td>{this.props.reportname}</td>
                <td >{this.props.createname}</td>
                <td >{this.props.createtime}</td>
                <td><div className="trButton table-select trLeft trLong" onClick={this.props.onClickQueryTable}>导出查看</div><div className="trButton trLeft table-delete table-select" onClick={this.props.onClickDeleteTable}>删除</div></td>
            </tr>
        );
    }
});
//父组件
var Main = React.createClass({
    //组件初始状态
    getInitialState: function () {
        return {otherData:this.props.otherData,tableData:this.props.tableData,detailsPageData:this.props.detailsPageData,schoolData:this.props.schoolData,schoolDataAll:this.props.schoolDataAll}
    },
    componentDidMount: function () {
        //使用ajax取出数据然后组装数据列表
        var svar = this;
        suixun.ajax(serverUrl+'/reportController/queryCustomReportList.json?param={pagenumber:1,pagecount:"'+pagecount+'"}','',"get",function(data){
            setTimeout(function () {
                suixun.hideLoding();//隐藏加载中
            },500);
            if(data.code == 200){
                if(data.info.queryresult != null){
                    for(var i=0;i<data.info.queryresult.length;i++){
                        var obj=data.info.queryresult[i];
                        tableData[i] = {key:i,reportname:obj.reportname,createname:obj.createname,createtime:obj.createtime,reportid:obj.reportid};
                    }
                    var pageRight = 0;
                    if(data.info.totlepage > 1){
                        pageRight = 1
                    }
                    otherData.pageLeft = 0;
                    otherData.pageRight = pageRight;
                    currentpage = 1;totlepage = data.info.totlepage;//初始化的时候赋值：分页的当前页和总的页数
                    svar.setState({tableData:tableData,otherData:otherData});
                }else{
                    otherData.pageLeft = 0;
                    otherData.pageRight = 0;
                    currentpage = 1;totlepage = 1;//初始化的时候赋值：分页的当前页和总的页数
                    svar.setState({tableData:tableData,otherData:otherData});
                }
                $("#devMassage").attr("checked","checked");//新增的时候默认设备管理选中
            }
            svar.selectSchoolData();//查询学校
        });
    },
    //查询学校数据
    selectSchoolData: function () {
        suixun.showLoding();//显示加载中
        var svar = this;
        suixun.ajax(serverUrl+'/schoolManage/querySchool.json','',"get",function(data){
            suixun.hideLoding();//隐藏加载中
            if(data.code == 200 ){
                for(var i=0;i<data.info.length;i++){
                    var obj=data.info[i];
                    schoolData[i] = {key:i,id:obj.id,schoolname:obj.schoolname};
                }
                schoolDataAll = schoolData;
                svar.setState({schoolData:schoolData,schoolDataAll:schoolDataAll});
            }else{
                svar.setState({schoolData:schoolData,schoolDataAll:schoolDataAll});
            }
        });
    },
    //分页
    onPageClick: function (num) {
        suixun.showLoding();//显示加载中
        //分页-调用ajac然后把数据查询出来:获取name的值
        //计算currentpage
        var onPageLeft = 0,onPageRight = 1,svar = this;
        if(num > 0){
            currentpage = num;
        }else if(num == -1 && currentpage > 1){
            currentpage --;
        }else if(num == -2  && currentpage < totlepage){
            currentpage ++;
        }
        //修改左右的按钮
        if((currentpage == totlepage && totlepage == 1)|| totlepage == 0){
            onPageLeft = 0;
            onPageRight = 0;
        }else if(currentpage == totlepage && totlepage > 1){
            onPageLeft = 1;
            onPageRight = 0;
        }else if(1 < currentpage && currentpage < totlepage){
            onPageLeft = 1;
            onPageRight = 1;
        }
        //执行ajax获取数据然后组装
        var param="param={";
        param = getJsonDataNotEmpty(param,"pagenumber",""+currentpage+"");
        param = getJsonDataNotEmpty(param,"pagecount",'"'+pagecount+'"');
        param += "}";
        suixun.ajax(serverUrl+'/reportController/queryCustomReportList.json',param,"get",function(data){
            suixun.hideLoding();//隐藏加载中
            if(data.code == 200){
                tableData = [];
                if(data.info.queryresult != null){
                    for(var i=0;i<data.info.queryresult.length;i++){
                        var obj=data.info.queryresult[i];
                        tableData[i] = {key:i,reportname:obj.reportname,createname:obj.createname,createtime:obj.createtime,reportid:obj.reportid};
                    }
                    if(data.info.totlepage > 1 && data.info.totlepage > currentpage){
                        onPageRight = 1
                    }else{
                        onPageRight = 0;
                    }
                    otherData.pageLeft = onPageLeft;
                    otherData.pageRight = onPageRight;
                    totlepage = data.info.totlepage;//初始化的时候赋值：分页的当前页和总的页数
                    svar.setState({tableData:tableData,otherData:otherData});
                }else{
                    otherData.pageLeft = 0;
                    otherData.pageRight = 0;
                    currentpage = 1;totlepage = 1;//初始化的时候赋值：分页的当前页和总的页数
                    svar.setState({tableData:tableData,otherData:otherData});
                }
            }
        });
    },
    //查询
    onClickQueryTable: function (info) {
        suixun.confirm_noTit("是否确定导出查看？",function (data) {
            if(data){
                window.location.href = "../reportController/export_reportList.json?param={reportid:"+info[0]+"}";
            }
        });
    },
    //删除自定义报表
    onClickDeleteTable: function (reportid) {
        var svar = this;
        suixun.confirm_noTit("是否删除？",function (data) {
            if(data){
                suixun.showLoding();//显示加载中
                var param="param={";
                param = getJsonDataNotEmpty(param,"reportid",""+reportid+"");
                param += "}";
                suixun.ajax(serverUrl+'/reportController/deleteReport.json',param,"get",function(data){
                    suixun.hideLoding(200);//隐藏加载中
                    if(data.code == 200){
                        suixun.alert("删除成功",function (data) {
                            if(data){
                                var tbodyData = $("#tbodyData").children();
                                if(tbodyData.length == 1 && currentpage > 1){
                                    totlepage = totlepage - 1;
                                    svar.onPageClick(currentpage-1);//更新数据
                                }else{
                                    svar.onPageClick(currentpage);//更新数据
                                }
                            }
                        })
                    }else{
                        suixun.alert("删除失败")
                    }
                });
            }
        });
    },
    /**
     * 新增报表
     */
    onClickAddTable: function () {
        $(".addReportFormPop").show();
        $(".pop-select").val("全部");

        var checked=event.srcElement.checked;
        $(".rightId_box").each(function(i,box) {
            box.checked= '';
        });
    },
    onClickHidePop: function () {
        $(".popPhone").hide();
        $("#school").val("");
        $(".pop-select").val("全部");
        $("#teacher").val("");
        $("#sdate").val("");
        $("#edate").val("");
        $("#reportname").val("");
        $(".rightId_box").attr("checked",false);
    },
    /**
     * 保存自定义报表
     */
    onClockSaveSchool: function () {
        var reportname = $("#reportname").val();//报表名称
        var school = $("#school").val();//学校名称
        var teacher = $("#teacher").val();//班主任手机号
        var orderType = $(".orderType option:selected").val();//购买明细表 发货状态
        var reporttype = "",
            provinceid = $("#provinceid").val(),//省
            cityid = $("#cityid").val(),//市
            countyid = $("#countyid").val();//区
        if(reportname == ""){
            $(".reportname-error").show();
            suixun.alert("报表名称不能为空!");
            return;
        }
        var devtype = $(".pop-select option:selected").val();

        if(devtype == "2.4G考勤卡"){
            devtype = 1;
        }else if(devtype == "智能学生证"){
            devtype = 2;
        }else if(devtype == "13.56考勤卡"){
            devtype = 3;
        }else{
            devtype = "";
        }
        if(otherData.tableType != 2){
            // if(provinceid != "" ){
            //     if(cityid == "" ){
            //         suixun.alert("选择地区");
            //         return;
            //     }else{
            //         if(countyid == "" ){
            //             suixun.alert("选择县或街道");
            //             return;
            //         }
            //     }
            // }
        }
        if(otherData.tableType == 1){
            if($("#teacher").val() != "" && $("#teacher").val().length != 11){
                suixun.alert("教师手机号码格式错误!");
                return;
            }
            orderType = "";
            reporttype = "1";
        }else if(otherData.tableType == 2){
            if(orderType == "全部"){
                orderType = 0;
            }else if(orderType == "未发货"){
                orderType = 2;
            }else if(orderType == "已发货"){
                orderType = 1;
            }
            school = "";
            teacher = "";
            countyid = "";
            cityid = "";
            provinceid = "";
            reporttype = "2";
            addTableStatus = "";
        }else{
            orderType = $(".orderTypeDiscount option:selected").val();
            if(orderType == "全部"){
                orderType = 0;
            }else if(orderType == "未配送"){
                orderType = 2;
            }else if(orderType == "已配送"){
                orderType = 1;
            }
            school = "";
            teacher = "";
            addTableStatus = "";
            reporttype = "3";
        }
        suixun.showLoding();//显示加载中
        var param;
        param="param={";
        param = getJsonDataNotEmpty(param,"name",""+reportname+"");//报表名称
        param = getJsonDataNotEmpty(param,"devtype",""+devtype+"");//设备类型
        param = getJsonDataNotEmpty(param,"orderstatus",""+orderType+"");//订单状态
        param = getJsonDataNotEmpty(param,"school",""+school+"");//学校
        if($("#sdate").val() == "" && $("#edate").val() != ""){
            param = getJsonDataNotEmpty(param,"edate","'"+$("#edate").val()+"'");
        }else if($("#edate").val() == "" && $("#sdate").val() != ""){
            param = getJsonDataNotEmpty(param,"sdate","'"+$("#sdate").val()+"'");
        }else if($("#edate").val()=="" && $("#sdate").val() == ""){
        }else{
            param = getJsonDataNotEmpty(param,"sdate","'"+$("#sdate").val()+"'");
            param = getJsonDataNotEmpty(param,"edate","'"+$("#edate").val()+"'");
        }
        param = getJsonDataNotEmpty(param,"teacher",""+teacher+"");//老师手机号
        param = getJsonDataNotEmpty(param,"status",""+addTableStatus+"");//设备状态
        param = getJsonDataNotEmpty(param,"reporttype",""+reporttype+"");//报表类型
        param = getJsonDataNotEmpty(param,"province",""+provinceid+"");//省
        param = getJsonDataNotEmpty(param,"city",""+cityid+"");//市
        param = getJsonDataNotEmpty(param,"town",""+countyid+"");//区
        param += "}";
        var svar = this;
        suixun.ajax(serverUrl+'/reportController/addReport.json',param,"get",function(data){
            suixun.hideLoding(200);//隐藏加载中
            if(data.code == 200){
                suixun.alert("保存成功",function (data) {
                    if(data){
                        svar.onPageClick(1);
                        svar.onClickHidePop();
                    }
                })
            }else{
                suixun.alert("保存失败")
            }
        });
    },
    //验证
    onBlurCompany: function (e) {
        if($("#reportname").val() == ''){
            $(".reportname-error").show();
        }else{
            $(".reportname-error").hide();
        }
    },
    //改变弹出层学校输入框
    onChangSchoolInput: function (e) {
        var val = $(e.target).val();
        if(val != ""){
            this.schoolArray(val);

        }else{
            $(".schoolList").hide();
        }
    },
    //排序
    schoolArray: function (val) {
        schoolData = [];
        for(var i = 0;i < schoolDataAll.length;i++){
            if((schoolDataAll[i].schoolname).indexOf(val) >= 0){
                schoolData.push({schoolname:schoolDataAll[i].schoolname});
            }
        }
        if(schoolData.length == 0){
            $(".schoolList").hide();
        }else{
            $(".schoolList").show();
            this.setState({schoolData:schoolData});
        }
    },
    //点击学校输入框
    onClickSchool: function () {
        var val = $("#school").val();
        this.schoolArray(val);
    },
    //点击报表类型
    onClickRadio: function(e){
        otherData.tableType = $(e.target).val();
        $("#reportname").val("");//报表名称
        $("#school").val("");//学校名称为空
        this.setState({otherData:otherData});
    },
    //导出缴费明细表
    exportReportList: function () {
        suixun.confirm_noTit("是否确定导出缴费明细表？",function (data) {
            if(data){
                window.location.href = "../reportController/export_reportList.json?param={pagenumber:1}";
            }
        });
    },
    //导出购买明细表
    exportReportPayList: function () {
        suixun.confirm_noTit("是否确定导出购买明细表？",function (data) {
            if(data){
                window.location.href = "../reportController/export_reportList.json?param={pagenumber:1,reporttype:2}";
            }
        });
    },
    //导出财务报表-显示弹出框
    exportReportFinance: function () {
        $('#sdateFinance').val('');
        $('#edateFinance').val('');
        $("input[name='typeFinance']:checked").attr("checked",false);//清空选中
        $('#sdateFinance,#edateFinance').datetimepicker({
            lang:'ch',
            timepicker:false,
            format:'Y-m-d',
            formatDate:'Y-m-d',
            minDate: '1950-01-01', // 最小
            maxDate: suixun.getFormatDate().substring(0,10) // 最大
        });
        $('.financePop').show();
    },
    /**
     * 导出财务报表
     */
    exportFinance: function () {
        var sdateFinance = $('#sdateFinance').val();
        var edateFinance = $('#edateFinance').val();
        var typeFinance = $("input[name='typeFinance']:checked").val();
        if(undefined == typeFinance){
            suixun.alert('请选择报表类型！');
            return;
        }
        var param = "param={";
        param = getJsonDataNotEmpty(param,"reporttype",'"'+typeFinance+'"');
        if(sdateFinance != ''){
            param = getJsonDataNotEmpty(param,"starttime",'"'+sdateFinance+'"');
        }
        if(edateFinance != ''){
            param = getJsonDataNotEmpty(param,"endtime",'"'+edateFinance+' 23:59:59"');
        }
        param += "}";
        window.location.href = "../reportController/exportFinanceReport.json?"+param;
    },
    /**
     * 改变时间
     */
    blurFinanceTimei: function (type,e) {
        var value = e.target.value;
        var newTime = suixun.getFormatDate();
        if(type == '1'){
            if(value == ''){
                $('#edateFinance').datetimepicker({
                    lang:'ch',
                    timepicker:false,
                    format:'Y-m-d',
                    formatDate:'Y-m-d',
                    minDate: '1950-01-01', // 最小
                    maxDate: newTime.substring(0,10) // 最大
                });
            }else{
                $('#edateFinance').datetimepicker({
                    lang:'ch',
                    timepicker:false,
                    format:'Y-m-d',
                    formatDate:'Y-m-d',
                    minDate: value, // 最小
                    maxDate: newTime.substring(0,10) // 最大
                });
            }
        }else{
            if(value == ''){
                $('#sdateFinance').datetimepicker({
                    lang:'ch',
                    timepicker:false,
                    format:'Y-m-d',
                    formatDate:'Y-m-d',
                    minDate: '1950-01-01', // 最小
                    maxDate: newTime.substring(0,10) // 最大
                });
            }else{
                // if(new Date(value) < new Date(newTime.substring(0,10))){
                //
                // }
                $('#sdateFinance').datetimepicker({
                    lang:'ch',
                    timepicker:false,
                    format:'Y-m-d',
                    formatDate:'Y-m-d',
                    maxDate: value, // 最大
                    minDate: '1950-12-30', // 最小
                });
            }
        }

    },
    /**
     * 验证输入框的长度
     * @returns {XML}
     */
    onInputNumber:function (e) {
        var value = e.target.value;
        if(value.length > 11){
            $(e.target).val(value.slice(0,11));
        }
    },
    render: function () {
        {
            var svar = this;
            var onClickArray = [this.onClickDeleteTable,this.onClickQueryTable];
            var Tabels = this.state.tableData.map(function (data,index) {
                return (
                    <Table key={data.key} listNumber={index} onClickQueryTable={onClickArray[1].bind(svar,[data.reportid,data.reportname])}  onClickDeleteTable={onClickArray[0].bind(svar,data.reportid)} reportid={data.reportid} reportname={data.reportname} createname={data.createname} createtime={data.createtime} />
                )
            })
        }
        return (
            <div className="tableManage-body">
                <div  className="pop popPhone popModel addReportFormPop">
                    <div className="model"></div>
                    <div className="pop-info popPhone-info popModel-info">
                        <div className="pop-title popModel-title">
                            <span className="pop-title-content popModel-title-content">
                                <span className="pop-title-content-solid-left popModel-title-content-solid-left"/>
                                 新增自定义报表
                                <span className="pop-title-content-solid-right popModel-title-content-solid-right"/>
                            </span>
                            <span className="pop-title-img popModel-title-img" onClick={this.onClickHidePop}><img src="../img/icon/close.png" alt="关闭"/></span>
                        </div>
                        <div className="pop-body popModel-body">
                            <div className="popModel-body-input">
                                <span className="popModel-body-input-title">报表类型</span>
                                <span className="popModel-body-radio-content "><input name="type" value="1" id="devMassage" type="radio" onClick={this.onClickRadio}/><span>设备管理</span></span>
                                <span className="popModel-body-radio-content onl-pay"><input name="type" value="2" type="radio" onClick={this.onClickRadio}/><span>线上购买</span></span>
                                <span className="popModel-body-radio-content onl-pay-doc"><input name="type" value="3" type="radio" onClick={this.onClickRadio}/><span>优惠订单</span></span>
                            </div>
                            <div className="popModel-body-input">
                                <span className="popModel-body-input-title">报表名称</span>
                                <span className="popModel-body-input-content">
                                    <input className="input-content " onBlur={this.onBlurCompany} maxLength="30" id="reportname" type="text" placeholder="请输入报表名称" />
                                </span>
                                <div className="errorMsg reportname-error" ></div>
                            </div>
                            <div className="popModel-body-input" style={{display:otherData.tableType==3?"none":"block"}}>
                                <span className="popModel-body-input-title">设备类型</span>
                                <span className="popModel-body-input-content">
                                    <select className="export-factory msgType pop-select" >
                                        <option value="全部" selected="selected" >全部</option>
                                        <option value="13.56考勤卡" >13.56考勤卡</option>
                                        <option value="智能学生证" >智能学生证</option>
                                        <option value="2.4G考勤卡" >2.4G考勤卡</option>
                                    </select>
                                </span>
                            </div>
                            <div className="popModel-body-input" style={{display:otherData.tableType==3?"block":"none"}}>
                                <span className="popModel-body-input-title">设备类型</span>
                                <span className="popModel-body-input-content">
                                    <select className="export-factory msgType pop-select-doc" >
                                        <option value="智能学生证" selected="selected">智能学生证</option>
                                    </select>
                                </span>
                            </div>
                            <div className="popModel-body-input" style={{display:otherData.tableType==2?"block":"none"}}>
                                <span className="popModel-body-input-title">订单状态</span>
                                <span className="popModel-body-input-content">
                                    <select className="export-factory orderType" >
                                        <option value="全部" selected="selected" >全部</option>
                                        <option value="已发货" >已发货</option>
                                        <option value="未发货" >未发货</option>
                                    </select>
                                </span>
                            </div>
                            <div className="popModel-body-input" style={{display:otherData.tableType==3?"block":"none"}}>
                                <span className="popModel-body-input-title">订单状态</span>
                                <span className="popModel-body-input-content">
                                    <select className="export-factory orderTypeDiscount" >
                                        <option value="全部" selected="selected" >全部</option>
                                        <option value="已配送" >已配送</option>
                                        <option value="未配送" >未配送</option>
                                    </select>
                                </span>
                            </div>
                            <div className="popModel-body-input" style={{display:otherData.tableType==2?"none":"block"}}>
                                <span className="popModel-body-input-title" style={{backgroundImage: "url()"}}>学校名称</span>
                                <span className="popModel-body-input-content" >
                                    <input className="input-content school" id="school" maxLength="50" onChange={this.onChangSchoolInput} onClick={this.onClickSchool}  type="text" placeholder="请输入学校关键字搜索" />
                                </span>
                                <div className="schoolList">
                                    {
                                        schoolData.map(function (data) {
                                            return (
                                                <span className="schoolList-value">{data.schoolname}</span>
                                            )
                                        })
                                    }
                                </div>
                            </div>
                            {
                                otherData.tableType==2?"":  <div className="popModel-body-input"><Address/></div>
                            }
                            <div className="popModel-body-input" style={{display:otherData.tableType==1?"block":"none"}}>
                                <span className="popModel-body-input-title" style={{backgroundImage: "url()"}}>班主任</span>
                                <span className="popModel-body-input-content" >
                                    <input className="input-content " id="teacher" type="number" onInput={this.onInputNumber} placeholder="请输入班主任手机号" />
                                </span>
                            </div>
                            <div className="pop-body-input time">
                                <span className="pop-body-input-title" style={{backgroundImage: "url()"}}>选择日期</span>
                                <div className="time-father">
                                    <span className="time-array">
                                        <span className="pop-body-input-content" >
                                            <input size="16" style={{marginTop: "0px",padding: "6px 10px"}} className="input-content inputTime inputTimeAdd" id="sdate" type="text" onClick={this.onClickTimer} placeholder="选择日期" value="" readonly />
                                        </span>
                                        <span className="line"/>
                                        <span className="pop-body-input-content timeRight" >
                                            <input size="16" style={{marginTop: "0px",padding: "6px 10px"}} className="input-content inputTime inputTimeAdd" id="edate" type="text" onClick={this.onClickTimer} placeholder="选择日期" value="" readonly />
                                        </span>
                                    </span>
                                </div>
                            </div>
                            <div className="jurisdiction" style={{display:otherData.tableType==1?"block":"none"}}>
                                <span className="jurisdiction-all">设备状态</span>
                                <div className="jurisdiction-list">
                                    <span title="激活" className="roleStyle" data-value="2">
                                        <input type="checkbox" className="rightId_box" data-value="2" value="on" />
                                        激活
                                    </span>
                                    <span title="已缴费" className="roleStyle" data-value="3">
                                        <input type="checkbox" className="rightId_box" data-value="3" value="on" />
                                        已缴费
                                    </span>
                                    <span title="已过期" className="roleStyle" data-value="4">
                                        <input type="checkbox" className="rightId_box" data-value="4" value="on" />
                                        已过期
                                    </span>
                                    <span title="未激活" className="roleStyle" data-value="1">
                                        <input type="checkbox" className="rightId_box" data-value="1" value="on" />
                                        未激活
                                    </span>
                                    {
                                        /**
                                         <span title="未缴费" className="roleStyle" data-value="5">
                                            <input type="checkbox" className="rightId_box" data-value="5" value="on" />
                                            未缴费
                                         </span>
                                         */
                                    }
                                    <span title="5天后过期" className="roleStyle" data-value="5">
                                        <input type="checkbox" className="rightId_box" data-value="5" value="on" />
                                        5天后过期
                                    </span>
                                </div>
                            </div>
                        </div>
                        <div className="pop-button">
                            <span className={otherData.tableType==2?"pop-button-ok onl-pay-but":"pop-button-ok"} onClick={this.onClockSaveSchool}>保存</span>
                        </div>
                    </div>
                </div>
                <div  className="pop popPhone popModel financePop">
                    <div className="model"></div>
                    <div className="pop-info popPhone-info popModel-info">
                        <div className="pop-title popModel-title">
                            <span className="pop-title-content popModel-title-content">
                                <span className="pop-title-content-solid-left popModel-title-content-solid-left"/>
                                    财务报表
                                <span className="pop-title-content-solid-right popModel-title-content-solid-right"/>
                            </span>
                            <span className="pop-title-img popModel-title-img" onClick={this.onClickHidePop}><img src="../img/icon/close.png" alt="关闭"/></span>
                        </div>
                        <div className="pop-body popModel-body">
                            <div className="popModel-body-input">
                                <span className="popModel-body-input-title">报表类型</span>
                                <span className="popModel-body-radio-content "><input name="typeFinance" value="yiji" type="radio" /><span>易极付</span></span>
                                <span className="popModel-body-radio-content onl-pay"><input name="typeFinance" value="wechat" type="radio" /><span>微信</span></span>
                            </div>
                            <div className="pop-body-input time">
                                <span className="pop-body-input-title" style={{backgroundImage: "url()"}}>选择日期</span>
                                <div className="time-father">
                                    <span className="time-array">
                                        <span className="pop-body-input-content" >
                                            <input size="16" className="input-content inputTime inputTimeFinance" id="sdateFinance" onBlur={this.blurFinanceTimei.bind(this,1)} type="text" onClick={this.onClickTimer} placeholder="开始日期" value="" readonly />
                                        </span>
                                        <span className="line"/>
                                        <span className="pop-body-input-content timeRight" >
                                            <input size="16" className="input-content inputTime inputTimeFinance" id="edateFinance" onBlur={this.blurFinanceTimei.bind(this,2)} type="text" onClick={this.onClickTimer} placeholder="截止日期" value="" readonly />
                                        </span>
                                    </span>
                                </div>
                            </div>

                        </div>
                        <div className="pop-button" style={{top:'8px'}}>
                            <span className='pop-button-ok' onClick={this.exportFinance}>导出报表</span>
                        </div>
                    </div>
                </div>
                <div className="list-page">
                    <div className="statistical-analysis">
                        <div className="statistical-analysis-top">
                            <div className="statistical-analysis-top-left">
                                <div className="statistical-analysis-top-left-title">常用报表</div>
                                <div className="statistical-analysis-top-left-text">
                                    <img src="../img/icon/annotations.png" />
                                    <span/>
                                    <div>这里是注释。</div>
                                </div>
                            </div>
                        </div>
                        <div className="statistical-analysis-content">
                            <div className="common-report">
                                <span className="common-report-list" onClick={this.exportReportList}>
                                    <img src="../img/icon/table.png" />
                                    <span>缴费明细报表</span>
                                </span>
                                <span className="common-report-list" onClick={this.exportReportPayList}>
                                    <img src="../img/icon/table.png" />
                                    <span>购买明细报表</span>
                                </span>
                                <span className="common-report-list" onClick={this.exportReportFinance}>
                                    <img src="../img/icon/table.png" />
                                    <span>财务报表</span>
                                </span>
                            </div>
                        </div>
                    </div>
                    <div className="statistical-analysis tableInfo">
                        <div className="statistical-analysis-top">
                            <div className="statistical-analysis-top-left">
                                <div className="statistical-analysis-top-left-title">自定义报表</div>
                                <div className="statistical-analysis-top-left-text">
                                    <img src="../img/icon/annotations.png" />
                                    <span/>
                                    <div>这里是注释。</div>
                                </div>
                            </div>
                            <div className="statistical-analysis-top-right-button">
                                <div className="header-right-select" onClick={this.onClickAddTable}><div className="school-or-table-user">新增报表</div></div>
                            </div>
                        </div>
                        <div className="studentsInfo tableInfo">
                            <div className="studentsInfo-data tableInfo-data">
                                <div className="studentsInfo-data-table tableInfo-data-table" >
                                    <table className="head-body head-body">
                                        <thead>
                                            <th>序号</th>
                                            <th>报表名称</th>
                                            <th>创建人</th>
                                            <th>创建日期</th>
                                            <th>操作</th>
                                        </thead>
                                        <tbody id="tbodyData">
                                            {this.state.tableData==""?'':Tabels}
                                        </tbody>
                                    </table>
                                    {this.state.tableData==""?<div className="tableNoData">{tableNoDataCount}</div>:''}
                                </div>
                            </div>
                        </div>
                        <Page otherData={this.state.otherData} onPageClick={this.onPageClick} />
                    </div>
                    <footer id="copyright">
                        <span><img src="../img/icon/copyright.png"/>{copyright}</span>
                    </footer>
                </div>
            </div>
        )
    }
});
/**
 * 获取行政区域组件开始
 * @type {*}
 */
var Address=React.createClass({
    getInitialState:function () {
        return{
            provinceData:[],
            cityData:[],
            countyData:[]
        };
    },
    queryAddress:function (num,province,city) {
        var param="param={";
        param = getJsonDataNotEmpty(param,"type",'"'+num+'"');
        param = getJsonDataNotEmpty(param,"province",'"'+province+'"');
        param = getJsonDataNotEmpty(param,"city",'"'+city+'"');
        param += "}";
        var svar = this;
        suixun.ajax(serverUrl+'/schoolManage/queryRegion.json',param,"get",function(data){
            if(data.code == 200){
                if(num == "1"){
                    var provinceData = [];
                    for(var i = 0 ;i < data.info.length;i++ ){
                        provinceData[i] = {value:data.info[i].province};
                    }
                    svar.setState({provinceData:provinceData});
                }else if(num == "2"){
                    var cityData = [];
                    for(var i = 0 ;i < data.info.length;i++ ){
                        cityData[i] = {value:data.info[i].city};
                    }
                    svar.setState({cityData:cityData});
                }else{
                    var countyData = [];
                    for(var i = 0 ;i < data.info.length;i++ ){
                        countyData[i] = {value:data.info[i].town};
                    }
                    svar.setState({countyData:countyData});
                }
            }
        });
    },
    //查询省份
    queryProvince:function () {
        if($("#province").find(".pop-address-content-selectData").css('display')=='none'&&this.state.provinceData.length>0){
            $("#province").find(".pop-address-content-selectData").css('display','block');
            $("#city").find(".pop-address-content-selectData").css('display','none');
            $("#county").find(".pop-address-content-selectData").css('display','none');
            return false;
        }else if(this.state.provinceData.length>0){
            $("#province").find(".pop-address-content-selectData").css('display','none');
            return false;
        }
        this.queryAddress(1,"","");
        $("#province").find(".pop-address-content-selectData").css('display','block');
    },
    queryCity:function () {
        if($("#provinceid").next().html()=='选择省份'||$("#province").find(".pop-address-content-selectData").css('display')=='block'){
            return false;
        }
        if($("#city").find(".pop-address-content-selectData").css('display')=='block'){
            $("#city").find(".pop-address-content-selectData").css('display','none');
            return false;
        }
        this.queryAddress(2,$(".span-provinceid").html(),"");
        $("#city").find(".pop-address-content-selectData").css('display','block');
        $("#county").find(".pop-address-content-selectData").css('display','none');
    },
    queryCounty:function () {
        if($("#provinceid").next().html()=='选择省份'||$("#cityid").next().html()=='选择地区'||$("#city").find(".pop-address-content-selectData").css('display')=='block'
            ||$("#province").find(".pop-address-content-selectData").css('display')=='block'){
            return false;
        }
        if($("#county").find(".pop-address-content-selectData").css('display')=='block'){
            $("#county").find(".pop-address-content-selectData").css('display','none');
            return false;
        }
        this.queryAddress(3,"",$(".span-cityid").html());
        $("#county").find(".pop-address-content-selectData").css('display','block');
    },
    render:function () {
        return(
            <div className="pop-body-input address">
                <span className="pop-body-input-title address-span" style={{backgroundImage:"url()"}}>地区</span>
                <div className="pop-address-contents">
                    <div className="pop-address-content" id="province">
                        <input type="hidden" id="provinceid"/>
                        <span className="pop-address-content-default text-sub span-provinceid" title="" onClick={this.queryProvince}>选择省份</span>
                        <AddressData type="1" resultData={this.state.provinceData}/>
                    </div>
                    <div  id="city" className="pop-address-content">
                        <input type="hidden" id="cityid"/>
                        <span className="pop-address-content-default text-sub span-cityid" title="" onClick={this.queryCity}>选择地区</span>
                        <AddressData type="2"  resultData={this.state.cityData}/>
                    </div>
                    <div id="county" className="pop-address-content">
                        <input type="hidden" id="countyid" value="" data-dataType="Number" data-require="true" data-msg="地区不能为空"/>
                        <span className="pop-address-content-default text-sub span-countyid" title="" onClick={this.queryCounty}>选择县或街道</span>
                        <AddressData type="3"  resultData={this.state.countyData}/>
                    </div>
                </div>
            </div>
        );
    }
});
/**
 * 省市区组装下拉列表
 * @type {*}
 */
var AddressData = React.createClass({
    componentDidMount:function () {
        $('.pop-address-content').hover(function () {
        },function () {
            $('.pop-address-content-selectData').css('display','none');
        });
    },
    handleClick:function (e) {
        if($(e.target).attr("data-type")=="1"){
            $("#city").find(".pop-address-content-default").html('选择地区');
            $("#county").find(".pop-address-content-default").html('选择县或街道');
            this.setState({cityData:[],countyData:[]});
        }else if($(e.target).attr("data-type")=="2"){
            this.setState({countyData:[]});
            $("#county").find(".pop-address-content-default").html('选择县或街道');
        }
        $(e.target).parent().prev().html(e.target.innerHTML);
        $($(e.target).parent().prev()).attr("title",e.target.innerHTML);
        $(e.target).parent().prev().prev().val(e.target.innerHTML);
        $($(e.target).parent()).hide();
    },
    render:function () {
        var svar = this;
        var resultDATA=this.props.resultData.map(function (value,index) {
            return(
                <span onClick={svar.handleClick} data-type={svar.props.type} >{value.value}</span>
            );
        });
        return(
            <div className="pop-address-content-selectData">
                {resultDATA}
            </div>
        );
    }
});
ReactDOM.render(
    <Main  otherData={otherData} tableData={tableData} schoolData={schoolData} schoolDataAll={schoolDataAll}/>,
    document.getElementById('tableManage')
);
$('.inputTimeAdd').datetimepicker({
    format: "Y-m-d", //格式化日期
    timepicker: false, //显示时间选项
    todayButton: false, //关闭选择今天按钮
    step:5,//时间间隔
});
/**
 * minData maxDate 不能使用压缩的版本
 */
$('#edateFinance,#sdateFinance').datetimepicker({
    lang:'ch',
    timepicker:false,
    format:'Y-m-d',
    formatDate:'Y-m-d',
    // minDate:'2017-06-28', // yesterday is minimum date
    maxDate:suixun.getFormatDate().substring(0,10), // and tommorow is maximum date calendar
});
//是否全选
$(".jurisdiction-list").on('click','.rightId_box',function () {
    var childsCheckBox = $(".jurisdiction-list").children();
    var b = 0;
    for(var i = 0;i<childsCheckBox.length;i++){
        var child = $(childsCheckBox[i]).children();
        if($(child[0]).is(':checked')){
            b ++;
        }
    };
    if(b == childsCheckBox.length){
        addTableStatus = "0";
    }else{
        if($(this).is(":checked")){
            $(".rightId_box").attr("checked",false);
            addTableStatus = $(this).attr("data-value");
            $(this).prop("checked",true);
        }else{
            addTableStatus = "";
            $(".rightId_box").attr("checked",false);
        }
    }
})
$("*").bind("click",function(e){
    var target = $(e.target);
    if(target.closest(".school").length == 1){

        return;
    }
    if(target.closest(".schoolList-value").length == 1){
        $("#school").val(target.html());
        $(".schoolList").hide();
    }else{
        $(".schoolList").hide();
    }
});
